home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11036 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news1.is.net!news
  2. From: Mark VanTassel <mvantassel@teambca.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Operator overloading
  5. Date: Tue, 12 Mar 1996 08:02:17 -0500
  6. Organization: Barfield, Cauthen and Associates
  7. Message-ID: <314575D9.3A2A@teambca.com>
  8. References: <313F19B5.41C6@lfa.uni-wuppertal.de>
  9. NNTP-Posting-Host: dynamic12.is.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. > const T& operator[](unsigned long int index) const;
  16. > I know, it is an subscription overloading, for something like
  17. > v[i], where i is of type unsigned long int and v of type T.
  18. > What's the meaning of the const at the end
  19. > and the beginning of the line ?
  20.  
  21. The const at the end says that this member function (it must be a member, since it only defines 
  22. one argument) cannot modify the state of the object to which it is being applied (the 
  23. pseudo-array which is being "indexed"). 
  24.  
  25. The const at the beginning says that the object (of type T) to which a reference is returned 
  26. cannot be modified by the caller of this "index" operation.
  27.  
  28. (Note that both can be overridden by casting the constness away. This should NEVER be done, 
  29. except in certain circumstances ;-)
  30.